var t = getApp()
Page({
  data: {
    iconsUrl:t.globalData.iconsUrl,
    resort:false,
    list:[],
    navHeight:t.globalData.navHeight,
    title:'我的余额',
    search:'',
    lat:'',
    lon:'',
  },
  onLoad: function (options) {
    let that = this
    wx.getLocation({
      type: 'gcj02',
      success (res) {
        that.setData({
          lat:res.latitude,
          lon:res.longitude
        })
        that.getlist() //获取门店列表
      },
      fail: function (res) {
        wx.showToast({
          title: '请开启手机定位服务以提供更好的体验',
          icon: 'none',
          duration: 5500,
        });
        console.error('获取位置信息失败：',res);
       }
    })
  },
  onShow(e){
    if (t.globalData.show_tel_login) {
      t.showTelLogin()
      return;
    }
  },

  // input
  bindKeyInput: function (e) {
    console.log('confirm')
    this.setData({
      search: e.detail.value
    })
  },
  onRefresh(){
    //在当前页面显示导航条加载动画
    //显示 loading 提示框。需主动调用 wx.hideLoading 才能关闭提示框
    this.getlist()
  },
  onPullDownRefresh: function () {
    //调用刷新时将执行的方法
    this.onRefresh();
    setTimeout(function () {
      // 不加这个方法真机下拉会一直处于刷新状态，无法复位
      wx.stopPullDownRefresh()
    }, 1000)
  },
  getlist(e){
    var that = this
    var obj = {
        page:1,
        size:200,
        search:that.data.search,
        lng:that.data.lon,
        lat:that.data.lat
    }
    t.request('/store/myBalance',obj,function(e){
      console.log(e);
      if (e.code==200) {
        if (e.result.total>0) {
          var a = e.result
          that.setData({
            list:a.list,
            describe:a.describe
          })
        }
      }else{
        wx.showToast({
          title: e.msg,
          icon:'none'
        })
      }
    })
  },
  to_invest(e){
    wx.navigateTo({
      url: '/pages/personCenter/chooseStore/invest/invest?store_id=' + e.currentTarget.dataset.store_id,
    })
  },


})